package org.kailu.book.DAO;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.kailu.book.entity.ExportEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ExportDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	public void save(ExportEntity exportEntity) {
		this.sessionFactory.getCurrentSession().saveOrUpdate(exportEntity);
	}
	
	@SuppressWarnings("unchecked")
	public List<ExportEntity> getAll() {
		return this.sessionFactory.getCurrentSession().createCriteria(ExportEntity.class).add(Restrictions.eq("verify", 1)).list();
	}
	
	@SuppressWarnings("unchecked")
	public List<ExportEntity> getAllUnverify() {
		return this.sessionFactory.getCurrentSession().createCriteria(ExportEntity.class).add(Restrictions.eq("verify", 0)).list();
	}
	
	public ExportEntity get(int id) {
		return (ExportEntity) this.sessionFactory.getCurrentSession().get(ExportEntity.class, id);
	}
	
	public void delete(int id) {
		ExportEntity exportEntity = (ExportEntity) this.sessionFactory.getCurrentSession().get(ExportEntity.class, id);
		
		if (exportEntity != null) {
			this.sessionFactory.getCurrentSession().delete(exportEntity);
		}
	}
	
}
